package com.tyut.homework.controller;

import com.tyut.homework.pojo.FinanceHandle;
import com.tyut.homework.response.ServerResponse;
import com.tyut.homework.service.FinanceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api("财产管理")
@RestController
@RequestMapping("/finance")
public class FinanceController extends ControllerTemplate<FinanceHandle> {

    @Autowired
    private FinanceService financeService;

    @ApiOperation("查询单个")
    @GetMapping("/findById/{id}")
    public ServerResponse findById(@PathVariable Integer id){
        return ServerResponse.createBySuccess(financeService.find(id));
    }
    @ApiOperation("查看分页信息")
    @GetMapping("/findAll/{pageNum}/{pageLimit}")
    public ServerResponse findAll(@PathVariable Integer pageNum,
                                           @PathVariable Integer pageLimit){
        return ServerResponse.createBySuccess(financeService.getPage(pageNum, pageLimit));
    }

    @ApiOperation("添加")
    @PostMapping("/add")
    public ServerResponse add(FinanceHandle financeHandle ){
        return ServerResponse.createBySuccess(financeService.save(financeHandle ));
    }

    @ApiOperation("更新信息")
    @PostMapping("/update")
    public  ServerResponse update(FinanceHandle financeHandle ){
        return ServerResponse.createBySuccess(financeService.update(financeHandle ));
    }

    @ApiOperation("删除单个")
    @GetMapping("/delete/{id}")
    public  ServerResponse delete(@PathVariable Integer id){
        return ServerResponse.createBySuccess("delete success", financeService.delete(id));
    }
}
